package com.skp.plastory;

import java.util.ArrayList;

import android.app.ListActivity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class ListTest extends ListActivity {
	private ArrayList<String> list;
	private ArrayAdapter<String> adapter;
	private EditText inputText;
	private Button inputButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_test);

		inputText = (EditText) findViewById(R.id.inputText);
		inputButton = (Button) findViewById(R.id.inputButton);
		list = new ArrayList<String>();

		inputButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				list.add(inputText.getText().toString());
				inputText.setText("");
				adapter.notifyDataSetChanged();
			}

		});

		adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);

		setListAdapter(adapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Toast.makeText(getApplicationContext(), list.get(position), Toast.LENGTH_SHORT).show();
	}
}